/* (swing1.1beta3) */
package com.hardson.toolkit.swing.table;

import java.util.Enumeration;
import java.util.Vector;

import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;

/**
 * GroupableTableHeader
 *
 * @version 1.0 10/20/98
 * @author Nobuo Tamemasa
 */
class GroupableTableHeader extends JTableHeader {
	private static final long serialVersionUID = 1L;

	//private static final String uiClassID = "GroupableTableHeaderUI";
	protected Vector<ColumnGroup> columnGroups = null;

	public GroupableTableHeader(final TableColumnModel model) {
		super(model);
		this.setUI(new GroupableTableHeaderUI(this));
		this.setReorderingAllowed(false);
	}

	@Override
	public void setReorderingAllowed(final boolean b) {
		this.reorderingAllowed = false;
	}

	public void addColumnGroup(final ColumnGroup g) {
		if (this.columnGroups == null) {
			this.columnGroups = new Vector<ColumnGroup>();
		}
		this.columnGroups.addElement(g);
	}

	public Enumeration<?> getColumnGroups(final TableColumn col) {
		if (this.columnGroups == null) {
			return null;
		}
		Enumeration<ColumnGroup> em = this.columnGroups.elements();
		while (em.hasMoreElements()) {
			ColumnGroup cGroup = em.nextElement();
			Vector<?> v_ret = cGroup.getColumnGroups(col, new Vector<ColumnGroup>());
			if (v_ret != null) {
				return v_ret.elements();
			}
		}
		return null;
	}

	public void setColumnMargin() {
		if (this.columnGroups == null) {
			return;
		}
		int columnMargin = this.getColumnModel().getColumnMargin();
		Enumeration<ColumnGroup> em = this.columnGroups.elements();
		while (em.hasMoreElements()) {
			ColumnGroup cGroup = em.nextElement();
			cGroup.setColumnMargin(columnMargin);
		}
	}

}
